@extends('admin.common.web')

@section('title','会员列表')

@section('style')
    <style type="text/css">
        .pageList {
            text-align: center;
            margin-top: 2%;
        }
    </style>
@endsection

@section('content')
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <a href="#">系统</a>
            </li>
            <li class="active">会员管理</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->

    <!-- Page Body -->
    <div class="page-body">
        @include('admin.common.msg')

        {{--<button type="button" class="btn btn-sm btn-azure btn-addon" onClick="javascript:window.location.href = '{{ route('admin.article.create') }}'">--}}
        {{--<i class="fa fa-plus"></i> 添加会员--}}
        {{--</button>--}}

        <div class="row">
            <div class="col-lg-12 col-sm-12 col-xs-12">
                <div class="widget">
                    <div class="widget-body bordered-left bordered-warning">
                        <form class="form-inline" action="{{ route('admin.user.index') }}" role="form">
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputEmail2">Email address</label>
                                <input type="text" name="nickname" value="{{ request()->input('nickname') }}" class="form-control" id="exampleInputEmail2" placeholder="姓名">
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputEmail2">Email address</label>
                                <input type="text" name="username" value="{{ request()->input('username') }}" class="form-control" id="exampleInputEmail2" placeholder="手机号">
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputPassword2">Password</label>
                                <input type="text" name="company_name" value="{{ request()->input('company_name') }}" class="form-control" id="exampleInputPassword2" placeholder="公司名">
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputPassword2">Password</label>
                                <select name="admin_id">
                                    <option value="">选择录入员</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputPassword2">Password</label>
                                <select name="status">
                                    <option value="">选择状态</option>
                                    <option value="1" @if(request()->input('status') == '1') selected @endif>有效</option>
                                    <option value="0" @if(request()->input('status') == '0') selected @endif>无效</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputPassword2">Password</label>
                                <input type="text" name="start_time" class="form-control" id="start_time" autocomplete="off" value="{{ request()->input('start_time') }}" placeholder="注册开始时间">
                            </div>
                            <div class="form-group">
                                <label class="sr-only" for="exampleInputPassword2">Password</label>
                                <input type="text" name="end_time" class="form-control" id="end_time" autocomplete="off" value="{{ request()->input('end_time') }}" placeholder="注册结束时间">
                            </div>
                            <button type="submit" class="btn btn-default">搜索</button>
                            <span style="margin-left: 10px">共 {{ $count }}条数据</span>
                        </form>

                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-sm-12 col-xs-12">
                <div class="widget">
                    <div class="widget-body">
                        <div class="flip-scroll">
                            <table class="table table-bordered table-hover">
                                <thead class="">
                                <tr>
                                    <th class="text-center">ID</th>
                                    <th class="text-center">头像</th>
                                    <th class="text-center">用户名</th>
                                    <th class="text-center">电话</th>
                                    <th class="text-center">性别</th>
                                    <th class="text-center">年龄</th>
                                    <th class="text-center">状态</th>
                                    <th class="text-center">创建时间</th>
                                    <th class="text-center">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($userList as $v)
                                    <tr>
                                        <td align="center">{{ $v['id'] }}</td>
                                        <td align="center">
                                            @if($v['thumb'])
                                                <img src="{{ asset($v['thumb']) }}" width="30" height="30"/>
                                            @else
                                                暂无图片
                                            @endif
                                        </td>
                                        <td align="center">{{ $v['username'] }}</td>
                                        <td align="center">{{ $v['tel'] }}</td>
                                        <td align="center">{{ $v['user_info']['sex'] == '0' ? '男' : '女' }}</td>
                                        <td align="center">{{ $v->user_info->age != 0 ? $v->user_info->age : '-' }}</td>
                                        <td align="center">
                                            <label>
                                                <input user_id="{{ $v['id'] }}" class="checkbox-slider toggle colored-success" @if($v['status'] == 1) checked @endif type="checkbox">
                                                <span class="text"></span>
                                            </label>
                                        </td>
                                        <td align="center">{{ $v['created_at'] }}</td>
                                        <td align="center">
                                            <a href="{{ route('admin.user.edit',['id'=>$v['id']]) }}" class="btn btn-primary btn-sm shiny">
                                                <i class="fa fa-edit"></i> 编辑
                                            </a>
                                            <a href="{{ route('admin.user.destroy',['id'=>$v['id']]) }}" onClick="return confirm('确定要删除吗？')" class="btn btn-danger btn-sm shiny">
                                                <i class="fa fa-trash-o"></i> 删除
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                        <div>
                        </div>

                        <div class="pageList">
                            {{ $userList->appends(request()->input())->links() }}
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
@endsection
@section('script')
    <script type="text/javascript" src="{{ asset('js/api_request.js') }}"></script>
    <script type="text/javascript">
        $(()=>{
            //ajax修改用户状态
            $('.checkbox-slider').click(async function () {
                let mybtn = $(this);
                let user_id = $(this).attr('user_id');

                let checked = $(mybtn).prop('checked');



                await requestData('{{ route("admin.user.ajaxChangeUserStatus") }}',{user_id:user_id},'post').then((res)=>{

                    if(res.data.status == 1){
                        $(mybtn).prop('checked',true);
                    }else{
                        $(mybtn).prop('checked',false);
                    }
                }).catch((res)=>{
                    if(checked){
                        $(mybtn).prop('checked',false);
                    }else{
                        $(mybtn).prop('checked',true);
                    }

                    alert(res.msg);
                })

            })
        })

        async function abc() {
            await requestData('http://wx.17hxg.com:21606/api/kill_goods/getInventory?id=136&sku_list=34,41').then(res=>{
                console.log(res);
            })
        }

        async function def() {
            await requestData('http://wx.17hxg.com:21606/api/kill_goods/getInventory?id=136&sku_list=34,42').then(res=>{
                console.log(res);
            })
        }
    </script>
@endsection
